<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'

export default {
  name: "scroll",
  props: {
    probeType: {
      type: Number,
      default: 0
    },
    pullUpLoad: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      scroll: null
    }
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      // 监听滚动位置
      probeType: this.probeType,
      // 监听上拉事件
      pullUpLoad: this.pullUpLoad,
      // 解决移动端滚动问题
      observeDOM: true,
      observeImage: true,
      click: true
      })

      // 监听滚动时触发事件
      this.scroll.on('scroll', (position) => {
        this.$emit('scroll', position);
      })

      // 监听上拉事件
      this.scroll.on('pullingUp', () => {
        this.$emit('pullingUp');
      })
  },
  methods: {
    scrollTo(x, y, time=300) {
      console.log("scrollTo")
      this.scroll.scrollTo(x, y, time)
    },
    finishPullUp() {
      this.scroll.finishPullUp()
    }
  }
}
</script>

<style scoped>

</style>